

package com.yuke.cloud.service.opc.mq.consumer;

import com.google.common.base.Preconditions;
import com.yuke.cloud.common.util.JacksonUtil;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.yuke.cloud.service.opc.service.OpcSendSmsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * The class Opc send sms topic consumer.
 *
 * @author
 */
@Slf4j
@Service
public class OpcSendSmsConsumer {

	@Resource
	private OpcSendSmsService opcSendsmsService;

	/**
	 * Handler send sms topic.
	 *
	 * @param body      the body
	 */
	public void handlerSendSms(String body) {
		Preconditions.checkArgument(!org.springframework.util.StringUtils.isEmpty(body), "发送短信失败, 消息体不能为空");
		SendSmsRequest sendSmsRequest;
		try {
			sendSmsRequest = JacksonUtil.parseJson(body, SendSmsRequest.class);
		} catch (Exception e) {
			log.error("发送短信MQ出现异常={}", e.getMessage(), e);
			throw new IllegalArgumentException("JSON转换异常", e);
		}
		String ipAddr = sendSmsRequest.getOutId();
		if (StringUtils.isEmpty(ipAddr)) {
			throw new IllegalArgumentException("outId不能为空");
		}
		opcSendsmsService.sendSms(sendSmsRequest);
	}
}
